package Year22_Month01.day0122;

public class Solution {
    public static String truncateSentence(String s, int k) {
        int count = 0;
        for(int i = 0;i < s.length();i++){
            if(k == count){
                return s.substring(0,i);
            }
            if(s.charAt(i) == ' '){
                count++;
            }
        }
        return s;
    }
    public static String truncateSentence2(String s, int k) {
        for(int i = 0;i < s.length();i++){
            if(s.charAt(i) == ' ' && --k == 0){
                return s.substring(0,i);
            }
        }
        return s;
    }
    public int removeDuplicates(int[] nums) {
        int slow = 0;
        int fast = 0;
        while(fast < nums.length){
            if(nums[fast] != nums[slow]){
                nums[++slow] = nums[fast];
            }
            fast++;
        }
        return slow+1;
    }

    public static void main(String[] args) {
        String s = "Hello how are you Contestant";
        System.out.println(truncateSentence(s,4));
    }
}
